package org.itli.jnsocket.Mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.itli.jnsocket.Pojo.Goods;
import org.itli.jnsocket.Pojo.WareHouse;

import java.math.BigInteger;
import java.util.List;

@Mapper
public interface NGoodsMapper {

    //--------------------------------所有信息事务----------------------------------------------
    @Select("select * from jn_wms_goods LIMIT #{size} OFFSET #{page}")
    List<Goods> AllGoods(int size,int page);
    //----------------------------------------------------------------------------------------

    //----------------------------查询在固定仓库中的商品数据--------------------------------------

    @Select("SELECT" +
            "    g.id AS id," +
            "    g.goods_sn AS goods_sn," +
            "    g.goods_name AS goods_name," +
            "    g.goods_spec AS goods_spec," +
            "    g.goods_price_in AS goods_price_in," +
            "    g.goods_price_out AS goods_price_out," +
            "    g.goods_status AS goods_status," +
            "    s.warehouse_id AS warehouse_id " +
            "FROM" +
            "    jn_wms_goods g " +
            "JOIN" +
            "    jn_wms_stock s ON g.id = s.goods_id " +
            "WHERE " +
            "    s.warehouse_id = #{warehouse_id}")
    List<Goods> AllGoodsInWarehouse(BigInteger warehouse_id);

    //----------------------------------------------------------------------------------------

    //---------------------------查询详细信息事务-----------------------------------------------

    //三表联查
    @Select("select * from jn_wms_goods where goods_sn = #{goods_sn}")
    Goods GetGoods(String goods_sn);

    @Select("select warehouse_name from jn_wms_warehouse where id = #{id}")
    String SelectWHName(int id);


    //---------------------------------------编辑商品事务-------------------------------------

    //获取仓库 id

    @Select("select id from jn_wms_warehouse where warehouse_name = #{warehouse_name}")
    int SelectWareHouseID(String warehouse_name);

    //更新商品表
    @Update("UPDATE jn_wms_goods " +
            "SET " +
            "    goods_name = #{goods.goods_name}, " +
            "    goods_spec = #{goods.goods_spec}, " +
            "    goods_price_in = #{goods.goods_price_in}, " +
            "    goods_price_out = #{goods.goods_price_out}, " +
            "    goods_status = #{goods.goods_status}, " +
            "    update_by = #{update_by}, " +
            "    update_time = NOW() " +
            "WHERE " +
            "    goods_sn = #{goods.goods_sn}")
    int UpdateGoodsInfo(Goods goods, String update_by);

    //更新库存表
    @Update("UPDATE jn_wms_stock " +
            "SET " +
            "    goods_stock = #{goods.goods_stock}, " +
            "    update_by = #{update_by}, " +
            "    update_time = NOW(), " +
            "    warehouse_id = #{goods.warehouse_id} " +
            "WHERE " +
            "    goods_sn = #{goods.goods_sn}")
    int UpdateGoodsStock(Goods goods, String update_by);


    //-------------------------添加商品事务--------------------------

    @Select("select id from jn_wms_goods_category where category_name = #{category_name}")
    int SelectCategoryID(String category_name);

    @Insert("INSERT INTO jn_wms_goods (goods_sn, goods_name, goods_spec, category_id,goods_price_in, goods_price_out, goods_status, create_by, create_time) " +
            "VALUES (#{goods.goods_sn},#{goods.goods_name}, #{goods.goods_spec}, #{category_id},#{goods.goods_price_in}, #{goods.goods_price_out}, #{goods.goods_status}, #{create_by}, NOW())")
    int InsertGoodsInfo(Goods goods, String create_by , int category_id);

    @Insert("INSERT INTO jn_wms_stock (goods_stock, goods_id ,goods_sn, create_by, create_time) " +
            "VALUES (#{goods.goods_stock}, #{goods_id},#{goods.goods_sn}, #{create_by}, NOW())")
    int InsertGoodsStock(Goods goods, String create_by, int goods_id);

    @Select("select id from jn_wms_goods where goods_sn = #{goods_sn}")
    int SelectGoodsId(String goods_sn);

    //---------------------添加仓库事务-------------------------




}
